﻿using System;
using System.Collections.Generic;
using System.Data;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ProjectSunny.Admin.Controls
{
    public partial class EditAddressFooter : System.Web.UI.UserControl
    {
        public string companyname;
        public string address;
        public string phone;
        public string fax;
        public string email;
        public int idcompany;
        protected void Page_Load(object sender, EventArgs e)
        {
            idcompany = Convert.ToInt32(Request.QueryString["companyid"]);
            DataTable dt = DAL.DCollector.DBCollector.Instance.StoredSelectTable("tbl_CompanyInfo");
            companyname = dt.Rows[0]["CompanyInfo_Name"].ToString();
            address = dt.Rows[0]["CompanyInfo_Add"].ToString();
            phone = dt.Rows[0]["CompanyInfo_Mobile"].ToString();
            fax = dt.Rows[0]["CompanyInfo_Fax"].ToString();
            email = dt.Rows[0]["CompanyInfo_Email"].ToString();

            txtNameCompany.Text = companyname;
            txtAddress.Text = address;
            txtPhone.Text = phone;
            txtFax.Text = fax;
            txtEmail.Text = email;

        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            if (txtNameCompany.Text != "")
            {
                if (txtAddress.Text != "")
                {
                    if (txtPhone.Text != "")
                    {
                        if (txtFax.Text != "")
                        {
                            if (txtEmail.Text != "")
                            {
                                if (txtNameCompany.Text.Length < 200)
                                {
                                    if (txtAddress.Text.Length < 200)
                                    {
                                        DAL.DHelpers.Column[] cl = new DAL.DHelpers.Column[5];
                                        cl[0] = new DAL.DHelpers.Column("CompanyInfo_Name", txtNameCompany.Text, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);
                                        cl[1] = new DAL.DHelpers.Column("CompanyInfo_Add", txtAddress.Text, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);
                                        cl[2] = new DAL.DHelpers.Column("CompanyInfo_Mobile", txtPhone.Text, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);
                                        cl[3] = new DAL.DHelpers.Column("CompanyInfo_Fax", txtFax.Text, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);
                                        cl[4] = new DAL.DHelpers.Column("CompanyInfo_Email", txtFax.Text, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);

                                        string colWhere =  "CompanyInfo_ID";

                                        string colValue = idcompany.ToString();

                                        DAL.DCollector.DBCollector.Instance.StoredUpdate("tbl_CompanyInfo", cl, colWhere, colValue);
                                        Response.Redirect("/Admin/Index.aspx?panel=7&sub=6");
                                    }
                                    else
                                    {
                                        Response.Write("<script>alert('Địa chỉ công ty tối đa 200 kí tự...')</script>");
                                    }
                                }
                                else
                                {
                                    Response.Write("<script>alert('Tên công ty tối đa 200 kí tự...')</script>");
                                }
                            }
                            else
                            {
                                Response.Write("<script>alert('Vui lòng nhập Email công ty...')</script>");
                            }
                        }
                        else
                        {
                            Response.Write("<script>alert('Vui lòng nhập số Fax công ty...')</script>");
                        }
                    }
                    else
                    {
                        Response.Write("<script>alert('Vui lòng nhập số Điện thoại công ty...')</script>");
                    }
                }
                else
                {
                    Response.Write("<script>alert('Vui lòng nhập Địa chỉ công ty...')</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('Vui lòng nhập Tên công ty...')</script>");
            }
        }
    }
}